/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rultax.blackice.example;

import com.rultax.blackice.Physics;
import com.rultax.blackice.ProcessingObject;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;
import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PVector;

/**
 * Simple example of creating a static boundry ProcessingObject.
 * 
 * @author rultax
 */
public class Boundary extends ProcessingObject{
    
    private float x;
    private float y;
    private float w;
    private float h;
    
    private Body body;
    
    /**
     * Creates a new instance of Boundary.
     * 
     * <p>
     * Provided dimension should all be in the screens coordinates.
     * 
     * @param x	Center x coordinate on the screen
     * @param y Center y coordinate on the screen
     * @param w Width in pixels
     * @param h Height in pixels
     * @param parent The screen to be displayed on
     * @param physics Physics provider
     */
    public Boundary(float x, float y, float w, float h, PApplet parent, Physics physics){
        super(parent, physics);
        
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
        
        float box2dw = getPhysics().scalarScreenToWorld(w / 2);
        float box2dh = getPhysics().scalarScreenToWorld(h / 2);
        PVector center = new PVector(x, y);
        
        PolygonShape ps = new PolygonShape();
        ps.setAsBox(box2dw, box2dh);
        
        BodyDef bd = new BodyDef();
        bd.position.set(getPhysics().coordScreenToWorld(center));
        bd.type = BodyType.STATIC;
        
        body = getPhysics().createBody(bd);
        body.createFixture(ps, 1.0f);
    }
    
    /**
     * 
     */
    @Override
    public void display(){
        getParent().fill(0);
        getParent().stroke(0);
        getParent().rectMode(PConstants.CENTER);
        getParent().rect(x, y, w, h);
    }
}
